from datetime import datetime

from sqlalchemy import Column, Integer, VARCHAR, ForeignKey, DateTime, Enum, Numeric, UniqueConstraint
from sqlalchemy.orm import relationship
from models.base_class import Base, gen_uuid


class Order(Base):
    """
    订单表
    """
    __tablename__ = 'orders'
    user_id = Column(VARCHAR(32), ForeignKey('users.user_id'), nullable=False, comment="用户id")
    order_date = Column(DateTime, default=datetime.utcnow, nullable=False, comment="订单日期")
    status = Column(Enum('pending', 'shipped', 'delivered', name='order_status'), default='pending', nullable=False,
                    comment="订单状态")
    total_amount = Column(Numeric(10, 2), nullable=False, comment="订单总金额")
    __table_args__ = ({'comment': '订单表'})

    # Relationship to User
    user = relationship('User', back_populates='orders')

    # Relationship to OrderDetails
    # order_details = relationship('OrderDetail', back_populates='order')
